﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;
using System.Data;
using DevExpress.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Models;
using DevExpress.Web.ASPxUploadControl;
using System.IO;
using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 工作日志
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class DailyController : AdminBaseController
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [AuthorityActionFilter("m_Daily", Order = 1)]
        [LogPageActionFilter("工作日志", Order = 2)]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult AddDa(int gowk)
        {
            ViewData["gowk"] = gowk;
            ViewData["prev"] = gowk - 1;
            ViewData["next"] = gowk + 1;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();
            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();

            DataSet ds = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = int.Parse(ds.Tables[0].Rows[0]["w"].ToString());
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();
            ViewData["user_name"] = OperateSession.get("UserName");

           

            string week = ViewData["week"].ToString();
            string year = ViewData["year"].ToString();
            Model.WeekPlan weekPlanModel = new Model.WeekPlan();
            if (!weekPlanBll.Exists(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO))
            {
                ViewData["content"] = "";
            }
            else
            {
                weekPlanModel = weekPlanBll.GetModel(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO);
                ViewData["content"] = weekPlanModel.FContent;

                ViewData["lastUpdate"] = "<span>最后更新时间:" + weekPlanModel.FUpdDate.ToString("yyyy-MM-dd") + "</span>";
                if (weekPlanModel.FStatus == "")
                {
                    ViewData["lastUpdate"] += "未审</div>";
                }
                else if (weekPlanModel.FStatus == "N")
                {
                    ViewData["lastUpdate"] += "审核未通过</div>";

                }
            }

            DataSet dstimediff = weekPlanBll.GetTimeDiff(gowk);

            BLL.Daily dailyBll = new BLL.Daily();
            DataSet dsallday;
            string allday = string.Empty;
            List<string> lsdsallday = new List<string>();
            string[] arrallday = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
            for (int i = 0; i < 7; i++)
            {
                dsallday = dailyBll.GetAllDay(i, gowk);
                if (DateTime.Parse(dsallday.Tables[0].Rows[0]["wk"].ToString()) <= DateTime.Now.Date)
                {
                    allday = dsallday.Tables[0].Rows[0]["wk"].ToString() + arrallday[i];
                    lsdsallday.Add(allday);
                }
                else
                {
                    if (i == 0 && int.Parse(dstimediff.Tables[0].Rows[0]["d"].ToString()) < -2)
                    {
                        Response.Write("<script>alert('您不能提前登记工作日志！');window.location.href ='" + Url.Action("WeekPlanList", "WeekPlan", new { gowk = 0 }) + "'</script>");
                        Response.Flush();
                        Response.End();
                    }
                    break;
                }
            }
            BLL.WorkCalendar workCalendarBll = new BLL.WorkCalendar();
            List<Model.WorkCalendar> workCalendarList = workCalendarBll.GetModelList(" Fdeftype <> '1' ");
            List<string> noWork = new List<string>();
            foreach (Model.WorkCalendar model in workCalendarList)
            {
                noWork.Add(model.FWorkDate.ToString("yyyy.MM.dd") + ChineseByEnWeek(model.FWorkDate));

            }

            foreach (string work in noWork)
            {
                lsdsallday.Remove(work);
            }
            ViewData["allday"] = lsdsallday;
            ViewData["cou"] = lsdsallday.Count();

            if (!weekPlanBll.Exists(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO))
            {
                ViewData["lastUpdate"] = "";
            }
            else
            {
                ViewData["lastUpdate"] = "<div>最后更新时间:" + weekPlanModel.FUpdDate.ToString("yyyy-MM-dd");
                if (weekPlanModel.FStatus == "")
                {
                    ViewData["lastUpdate"] += "未审</div>";
                }
                else if (weekPlanModel.FStatus == "N")
                {
                    ViewData["lastUpdate"] += "未通过请更新</div>";

                }
            }
            Model.Daily dailyModel = new Model.Daily();

            ViewData["type"] = "";
            List<string> contentList = new List<string>();
            //ViewData["FContent"] = "";
            ViewData["FUpDate"] = "";

            for (int i = 0; i < lsdsallday.Count; i++)
            {
                dailyModel = dailyBll.GetModel(DateTime.Parse(lsdsallday[i]), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO);
                if (dailyModel == null)
                {
                    dailyModel = new Model.Daily();
                    dailyModel.FContent = "";
                    ViewData["up" + i.ToString()] = true;
                    ViewData["type"] += "add,";
                    //ViewData["FContent"] += ",";

                    ViewData["FUpDate"] += "未更新,";
                }
                else
                {
                    if (dailyModel.FUpdDate == null)
                    {
                        ViewData["up" + i.ToString()] = true;
                    }
                    else
                    {
                        ViewData["up" + i.ToString()] = false;
                    }

                    ViewData["type"] += "edit,";
                    ViewData["id"] += dailyModel.FDailyID.ToString() + ",";
                    if (dailyModel.FUpdDate == null)
                    {
                        ViewData["FUpDate"] += ",";
                    }
                    else
                    {
                        ViewData["FUpDate"] += DateTime.Parse(dailyModel.FUpdDate.ToString()).ToString("yyyy.MM.dd") + ",";
                    }

                }
                contentList.Add(dailyModel.FContent);

            }
            ViewData["contentList"] = contentList;
            return View(dailyModel);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string ChineseByEnWeek(DateTime dt)
        {
            switch (dt.DayOfWeek.ToString())
            {
                case "Monday":
                    return "星期一";
                case "Tuesday":
                    return "星期二";
                case "Wednesday":
                    return "星期三";
                case "Thursday":
                    return "星期四";
                case "Friday":
                    return "星期五";
                case "Saturday":
                    return "星期六";
                case "Sunday":
                    return "星期日";
                default: return "";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="weekPlanModel"></param>
        /// <returns></returns>
        [ValidateInput(false)]
        public ActionResult SaveDaily(Model.Daily dailyModel)
        {
            ViewData["user_name"] = Fetch.Post("hiduser_name");
            ViewData["prev"] = Fetch.Post("hidprev");
            ViewData["next"] = Fetch.Post("hidnext");
            ViewData["week"] = Fetch.Post("hidweek");
            ViewData["wk"] = Fetch.Post("hidwk");
            ViewData["wk1"] = Fetch.Post("hidwk1");
            ViewData["lastUpdate"] = Fetch.Post("hidlastUpdate");
            ViewData["content"] = Fetch.Post("hidcontent");
            ViewData["gowk"] = Fetch.Post("hidgowk");
            ViewData["FContent"] = Fetch.Post("hidFContent");
            ViewData["FUpDate"] = Fetch.Post("hidFUpDate");
            ViewData["year"] = Fetch.Post("hidyear");

            BLL.Daily dailyBll = new BLL.Daily();
            DataSet dsallday;
            string allday = string.Empty;
            List<string> lsdsallday = new List<string>();
            string[] arrallday = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
            for (int i = 0; i < 7; i++)
            {
                dsallday = dailyBll.GetAllDay(i, int.Parse(Fetch.Post("hidgowk")));
                if (DateTime.Parse(dsallday.Tables[0].Rows[0]["wk"].ToString()) <= DateTime.Now.Date)
                {
                    allday = dsallday.Tables[0].Rows[0]["wk"].ToString() + arrallday[i];
                    lsdsallday.Add(allday);
                }
                else
                {
                    break;
                }

            }
            BLL.WorkCalendar workCalendarBll = new BLL.WorkCalendar();
            List<Model.WorkCalendar> workCalendarList = workCalendarBll.GetModelList(" Fdeftype <> '1' ");
            List<string> noWork = new List<string>();
            foreach (Model.WorkCalendar model in workCalendarList)
            {
                noWork.Add(model.FWorkDate.ToString("yyyy.MM.dd") + ChineseByEnWeek(model.FWorkDate));

            }

            foreach (string work in noWork)
            {
                lsdsallday.Remove(work);
            }
            ViewData["allday"] = lsdsallday;


            ViewData["last"] = Fetch.Post("hidlast");
            ViewData["cou"] = Fetch.Post("hidcou");
            string[] id = Fetch.Post("hidid").ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            string[] type = Fetch.Post("hidtype").ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                List<string> contentList = new List<string>();
                for (int i = 0; i < int.Parse(ViewData["cou"].ToString()); i++)
                {
                    if (type[i] == "add")
                    {
                        bool upcheck = CheckBoxExtension.GetValue<bool>("up" + i.ToString());

                        if (upcheck)
                        {
                            dailyModel.FDailyID = dailyModel.FDailyID;
                            dailyModel.FEmplNo = OperateSession.get("FEmplNo");
                            dailyModel.FEntityNo = GlobalConstant.ENTITYNO;
                            dailyModel.FDate = DateTime.Parse(lsdsallday[i]);
                            dailyModel.FContent = checkStr(NoHTML(Fetch.Post("FContent" + i).Trim()));
                            dailyModel.FInsDate = DateTime.Now;
                            dailyModel.FUpdDate = DateTime.Now;
                            dailyModel.FInsIP = Common.GenerateUtil.GetClientIPv4Address();

                            if (dailyModel.FContent != "")
                            {
                                dailyBll.Add(dailyModel);
                            }
                            contentList.Add(dailyModel.FContent);
                            if (dailyModel.FUpdDate == null)
                            {
                                ViewData["up" + i.ToString()] = true;
                            }
                        }
                        else
                        {
                            contentList.Add("");
                        }

                    }
                    else if (type[i] == "edit")
                    {
                        bool upcheck = CheckBoxExtension.GetValue<bool>("up" + i.ToString());

                        if (upcheck)
                        {
                            dailyModel.FDailyID = decimal.Parse(id[i]);
                            dailyModel.FUpdDate = DateTime.Now;
                            dailyModel.FContent = checkStr(NoHTML(Fetch.Post("FContent" + i).Trim()));

                            if (dailyModel.FContent != "")
                            {
                                dailyBll.Update(dailyModel);
                            }
                            contentList.Add(dailyModel.FContent);
                        }
                        else
                        {
                            contentList.Add("");
                        }
                    }

                    ViewData["up" + i.ToString()] = false;
                }
                ViewData["contentList"] = contentList;
                ViewData["message"] = "操作成功";
                ViewData["IsClose"] = "Y";
            }
            catch (Exception)
            {

                ViewData["message"] = "操作失败";
                ViewData["IsClose"] = "N";
            }
            ViewData["type"] = type;
            ViewData["id"] = Fetch.Post("hidid");



            return View("AddDa", dailyModel);
        }
        /// <summary>
        /// 替换Html
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public string checkStr(string html)
        {
            System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex10 = new System.Text.RegularExpressions.Regex(@"/(<textarea[^>]+>).*?(<\/textarea>)/gi", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            html = regex1.Replace(html, ""); //过滤<script></script>标记 
            html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性 
            html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件 
            html = regex4.Replace(html, ""); //过滤iframe 
            html = regex5.Replace(html, ""); //过滤frameset 
            html = regex6.Replace(html, ""); //过滤frameset 
            html = regex7.Replace(html, ""); //过滤frameset 
            html = regex8.Replace(html, ""); //过滤frameset 
            html = regex9.Replace(html, "");
            html = regex10.Replace(html, "");
            html = html.Replace(" ", "");
            html = html.Replace("</strong>", "");
            html = html.Replace("<strong>", "");
            return html;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Htmlstring"></param>
        /// <returns></returns>
        private string NoHTML(string Htmlstring)
        {
            //删除脚本
            Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
            //删除HTML
            //Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "\r\n", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
            Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
            Htmlstring.Replace("<", "");
            Htmlstring.Replace(">", "");
            Htmlstring.Replace("\r\n", "\r\n");
            return Htmlstring;
        }

        /// <summary>
        /// 桌面视图
        /// </summary>
        /// <returns>桌面视图</returns>
        public ActionResult DeskWeekPlanView()
        {

            //判断是否具有工作日志的菜单权限
            BLL.Index adminIndexBLL = new BLL.Index();
            string loginID = OperateSession.get(GlobalConstant.PARAM_LOGINID);

            List<Model.PrvFunctList> prvFunctiListList = new List<Model.PrvFunctList>();
            if (loginID == "admin")
            {
                prvFunctiListList = adminIndexBLL.GetPrvFunctList();
            }
            else
            {
                prvFunctiListList = adminIndexBLL.GetPrvFunctList(loginID);
            }
            prvFunctiListList = prvFunctiListList.Where(s => s.FFunctNo == "m_WeekPlan").ToList();

            if (prvFunctiListList.Count == 0)
            {
                return null;
            }
            int lr = 0;
            int flag = -1;
            BLL.Daily dailyBll = new BLL.Daily();
            DataSet dsday;
            DataSet dshol;
            for (int i = 0; i < 14; i++)
            {
                dsday = dailyBll.GetDay(i);
                DateTime dt = DateTime.Parse(dsday.Tables[0].Rows[0]["wk"].ToString());
                DateTime dt1 = DateTime.Parse("2011-05-29");
                if (dt <= dt1)
                {
                    lr++;
                    continue;
                }
                 string pd = dailyBll.Pd(dt);
                 if (pd == "1")
                 {
                     if (i <= 6 && !dailyBll.Exists(GlobalConstant.ENTITYNO, OperateSession.get("FEmplNo"), dt))
                     {
                         flag = -2;
                     }
                 }
                if (dailyBll.Exists(GlobalConstant.ENTITYNO, OperateSession.get("FEmplNo"), dt))
                {
                    lr++;
                }
                else
                {
                    dshol = dailyBll.GetHol(dt);
                    if (dshol.Tables[0].Rows.Count > 0)
                    {
                        if (dshol.Tables[0].Rows[0]["cou"].ToString() == "1")
                        {
                            lr++;
                        }
                        else
                        {
                            if (i <= 6)
                            {
                                flag = -2;
                            }
                        }
                    }
                }

            }

            if (14 - lr == 0)
            {
                flag = 0;
            }
            ViewData["tianshu"] = "";
            if (14 - lr > 0)
            {
                ViewData["tianshu"] = "<font size='2px' color='#174696'>(您还有</font><font size='2px' color='red'>" + (14 - lr).ToString() + "</font><font size='2px' color='#174696'>天工作情况未登记)</font>";
            }

            ViewData["flag"] = flag;


            int gowk = 0;
            BLL.WeekPlan weekPlanBll = new BLL.WeekPlan();

            DataSet dsdate = weekPlanBll.GetDate(gowk);
            ViewData["wk"] = dsdate.Tables[0].Rows[0]["wk"].ToString();
            ViewData["wk1"] = dsdate.Tables[0].Rows[0]["wk1"].ToString();


            DataSet ds = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["week"] = int.Parse(ds.Tables[0].Rows[0]["w"].ToString());
            DataSet dsyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            ViewData["year"] = dsyear.Tables[0].Rows[0]["y"].ToString();
            DataSet dsweek = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).ToString("yyyy-MM-dd"));
            Model.WeekPlan weekPlanModel = new Model.WeekPlan();
            DataSet dsnextWeek = weekPlanBll.GetTime(DateTime.Parse(ViewData["wk1"].ToString()).AddDays(7).ToString("yyyy-MM-dd"));
            ViewData["nextWeek"] = dsnextWeek.Tables[0].Rows[0]["w"].ToString();
            DataSet dsnextyear = weekPlanBll.GetYear(DateTime.Parse(ViewData["wk1"].ToString()).AddDays(7).ToString("yyyy-MM-dd"));
            ViewData["nextYear"] = dsnextyear.Tables[0].Rows[0]["y"].ToString();
            string week = ViewData["nextWeek"].ToString();
            string year = ViewData["nextYear"].ToString();
            ViewData["tishi"] = "";
            if (!weekPlanBll.Exists(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO))
            {
                ViewData["tishi"] = "<font size='2px' color='red'>计划未录入</font>";
            }
            else
            {
                weekPlanModel = weekPlanBll.GetModel(decimal.Parse(week), decimal.Parse(year), OperateSession.get("FEmplNo"), GlobalConstant.ENTITYNO);
                if (weekPlanModel.FStatus == "N")
                {
                    ViewData["tishi"] = "<font size='2px' color='red'>计划领导审核未通过</font>";
                }
                else if (weekPlanModel.FStatus == "Y")
                {
                    ViewData["tishi"] = "<font size='2px' color='red'>计划已审核</font>";
                }
                else
                {

                    ViewData["tishi"] = "<font size='2px' color='red'>计划领导未审核</font>";
                }
            }


            string emplNo = OperateSession.get("FEmplNo");

            ///此人是不是正级(副级)
            ///
            BLL.HREmpl emplBll = new BLL.HREmpl();
            bool istrue = emplBll.IsMainOrSub(emplNo);
            ViewData["isture"] = "false";
            if (istrue)
            {
                ViewData["isture"] = "true";
            }

            string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
            string entity = GlobalConstant.ENTITYNO;
            BLL.HREmpl hrEmplBLL = new BLL.HREmpl();
            //获取用户的所在部门，包括多岗位
            DataSet dsEmplDept = hrEmplBLL.GetEmplFromViewByEmplNo(emplNo, entity);
            List<string> deptNoList = new List<string>();

            if (dsEmplDept.Tables[0].Rows.Count > 0)
            {
                DataTable dt = dsEmplDept.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    deptNoList.Add(dt.Rows[i]["FDeptNo"].ToString());

                }

            }
            DataSet dsemp = weekPlanBll.GetEmpNoByDeptNoList(deptNoList);

            //DataSet dsemp = weekPlanBll.GetEmpNo(deptNo);
            DataSet dsnoauin = null;
            int cou = 0;
            if (dsemp.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsemp.Tables[0].Rows.Count; i++)
                {
                    dsnoauin = weekPlanBll.GetCou(dsemp.Tables[0].Rows[i]["FEmplNo"].ToString(), entity);
                    if (dsnoauin.Tables[0].Rows.Count > 0)
                    {
                        for (int j = 0; j < dsnoauin.Tables[0].Rows.Count; j++)
                        {
                            cou += int.Parse(dsnoauin.Tables[0].Rows[j]["cou"].ToString());
                        }
                    }
                }
            }
            else
            {
                dsnoauin = null;
            }

            ViewData["cou1"] = cou;


            return View();
        }


    }
}
